package cn.tedu.tmall.admin.mall.controller;

import cn.tedu.tmall.admin.mall.pojo.param.CategoryAddNewParam;
import cn.tedu.tmall.admin.mall.pojo.vo.CategoryListLtemVO;
import cn.tedu.tmall.admin.mall.pojo.vo.CategoryStandardVO;
import cn.tedu.tmall.admin.mall.service.ICategoryService;
import cn.tedu.tmall.common.pojo.vo.PageData;
import cn.tedu.tmall.common.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/categories")
@Api(tags = "1. 类别管理")
@Validated
@Slf4j
public class CategoryController {
    @Autowired
    private ICategoryService categoryService;

    @PostMapping("/add-new")
    @ApiOperation("新增类别")
    @ApiOperationSupport(order = 100)
    public JsonResult addNew(@Validated CategoryAddNewParam categoryAddNewParam){
        categoryService.addNew(categoryAddNewParam);
        return JsonResult.ok();
    }

    // TODO 根据ID删除类别
    // TODO 启用类别
    // TODO 禁用类别
    // TODO 显示类别
    // TODO 隐藏类别
    // TODO 修改类别详情
    // TODO 根据父级查询子级列表

    // http://localhost:8080/categories/250
    @GetMapping("/{id:[0-9]+}")
    @ApiOperation("根据id查询类别")
    @ApiOperationSupport(order = 410)
    @ApiImplicitParam(name = "id",value = "类别id",required = true,dataType = "long")
    public JsonResult selectById(@PathVariable @Range(min = 1, message = "请提交有效的类别ID值！") Long id){
        final CategoryStandardVO categoryStandardVO1 = categoryService.selectById(id);
        return JsonResult.ok(categoryStandardVO1);
    }

   // TODO 根据父级查询其子级列表,使用分页查询

}
